﻿using CommonType;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S_Incident.Domains.EventHandling;
using S_Incident.Domains.WorkflowEngine;
using S_Incident.Read.API.Application.Commands;
using System.Drawing.Drawing2D;

namespace S_Incident.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FormManagementReadController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<FormManagementReadController> logger;
        public FormManagementReadController(IMediator mediator, ILogger<FormManagementReadController> logger)
        {
            _mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 测试异常
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Test()
        {
            try
            {
                FormManagement management = null;
                management.FormName = "test";
                return Ok();
            }
            catch (Exception)
            {
                logger.LogError("赵乾安运行xxx任务时错误");
                throw;
            }
        }
        /// <summary>
        /// 测试Skywalking
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string FourNomalSend()
        {
            return "Testwords";
        }
        /// <summary>
        /// 对应行业枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult zhuanSheepBreed()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<Industry>())
            {
                list.Add(new
                {
                    value = item,
                    txt = item.ToString()
                });
            }
            return Ok(list);
        }
        /// <summary>
        /// 是否有效枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult zhuanEffective()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<Effective>())
            {
                list.Add(new
                {
                    value = item,
                    txt = item.ToString()
                });
            }
            return Ok(list);
        }
        /// <summary>
        /// 显示内容枚举
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult zhuanDisplayContent()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<DisplayContent>())
            {
                list.Add(new
                {
                    value = item,
                    txt = item.ToString()
                });
            }
            return Ok(list);
        }
        /// <summary>
        /// 处理时间
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetOptions()
        {
            // 从数据库或其他数据源获取字符串值
            string[] stringValues = { "自然日", "工作日", "自然时", "工作时" }; // 示例字符串值

            // 将字符串值转换为匿名对象数组
            var options = stringValues.Select(value => new { Text = value, Value = value });

            // 返回对象数组
            return Ok(options);
        }
        /// <summary>
        /// 绑定对应表单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<BindFormNameDto>> BinfFormName([FromQuery] BindFormNameCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 表单管理列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageResule<FormManagement>> ShowFormManagement([FromQuery]FormShowCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 流程管理列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageResule<FormManagementProcessDto>> ShowProcess([FromQuery]ProcessShowCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 显示我的事件信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageResule<NodeEventDispositionDto>> ShowMyEvent([FromQuery]EventDispositionCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 绑定下一级节点
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<BindNodeDto>> BindNode([FromQuery] BindNodeCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 我的事件反填
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResule<EventDisposition>> MyEventBackfill([FromQuery]EventDispositionBackfillCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 查询全部事件
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<EventDisposition>> ShowEvent([FromQuery]EventDisplayCommand command)
        {
            return await _mediator.Send(command);
        }


    }
}
